{% extends "baseD.html" %}

{% block headtitle %}- Calibrate PTZ Camera{% endblock %}

{% block divtitle %}- Calibrate PTZ Camera{% endblock %}

{% block css %}
	<link href="/live3dstatic/css/build.css" rel="stylesheet" type="text/css" media="screen" />
{% endblock %}

{% block scripts %}
	<script type="text/javascript" src="/live3dstatic/scripts/helperFunctions.js"></script>
	<script type="text/javascript" src="/live3dstatic/scripts/matrix.js"></script>
	<script type="text/javascript" src="/live3dstatic/scripts/simplex.js"></script>
	<script type="text/javascript" src="/live3dstatic/scripts/new_pantiltcalibration.js"></script>
	
	<script type="text/javascript">
		var ptzScene = null;
		var solution = null;
		var error = null;
		
		function initPTZ(){
			var origin = {lat: {{originLatitude}}, lon: {{originLongitude}}, alt: {{originAltitude}} };
			var panRange = new Array({{ptzScene.panLeftRange}}, {{ptzScene.panRightRange}});
			var tiltRange = new Array({{ptzScene.tiltDownRange}}, {{ptzScene.tiltUpRange}});
			var zoomRange = new Array({{ptzScene.zoomOutRange}}, {{ptzScene.zoomInRange}});
			ptzScene = new PTZScene({{ptzScene.index}}, origin, panRange, tiltRange, zoomRange, 
			                        {{ptzScene.width}}, {{ptzScene.height}}, 340, 120);
									
			{% for corr in corrs %}
				ptzScene.add_correspondence({{corr.index}}, {{corr.latitude}},{{corr.longitude}},{{corr.altitude}},
										  {{corr.u}},{{corr.v}},
										  {{corr.pan}},{{corr.tilt}},{{corr.zoom}});
			{% endfor %}
			
			//ptzScene.calibrate(20000, 10); // projection error
			var result = ptzScene.calibrate(20000, 0.0000001, {% if admin %}true{%else%}false{% endif %}, true); // angular error
			solution = result.solution;
			error = result.error;
		}
		
		
	</script>
{% endblock %}

{% block onload %}initPTZ(){% endblock %}

{% block content %}
	
    <div id="contentpage"  style="margin-left:40px; margin-right:40px;">
<p> Your scene is being calibrated.  You will soon be redirected to view your scene.  
If your browser doesn't redirect you after a few seconds, <a href='viewScene?scene={{ptzScene.index}}'>click here.</a> </p>
{% if admin %}
<div id="result"></div>

<br/>
<br/>

SIMPLEX output:
<div id="simplex"></div>
{% endif %}

    </div><!-- end contentpage --> 
{% endblock %}
		
{% block scripts2 %} {% endblock %}